<?php
namespace app\common\model;
use think\Model;
use fast\Cols;
use fast\Date;
use think\facade\Cache;
class School extends Model
{
	protected $pk = 'itemid';
	// 开启自动写入时间戳字段
	protected $autoWriteTimestamp = 'int';
	// 定义时间戳字段名
	protected $createTime = 'createtime';
	protected $updateTime = 'updatetime';
	public function getUpdatetimeValue($value){
		return Date::timetodate($value,3);
	}
	public function getCreatetimeValue($value){
		return Date::timetodate($value,3);
	}
	public function getSchoolByCache($itemid = 0){
		$con = array();$info = array();
		$bool = Cache::has('school'.$itemid);
		if($bool){
				//如果缓存存在
				$info = Cache::get('school'.$itemid);
		}else{
				//如果缓存不存在
				$info = $this->get($itemid);
				$arr = array();
				$arr['itemid'] = $itemid;
				$arr['name'] = $info?$info['name']:'';
				$arr['address'] = $info?$info['address']:'';
				Cache::set('school'.$itemid,$arr);
				$info = Cache::get('school'.$itemid);
		}
		return $info;
	}
	public function teacher(){
		return $this->hasMany('Teacher','schoolid','itemid');
	}
	}
?>
